﻿using Shinva.LADModel.Abstractions;
using Shinva.Variables.Interface;
using Shinva.Variables.Models;
using Shinva.Variables.Type.bit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Shinva.LADModel.Type.BitLogicOperations
{
    public class NContact : ElementNodeBase
    {

        public PlcBool operand { get; set; } = new PlcBool();
        public PlcBool bit { get; set; } = new PlcBool();
        //重写一下使能输出的值
        public override PlcBool EN
        {
            get
            {
                return en;
            }
            set
            {
                en = value;
            }
        }
        public override PlcBool ENO
        {
            get
            {

                eno.Value = en.Value && outLogic();
                return eno;
            }
            set
            {
                eno = value;
            }
        }

        public NContact()
        {
            Name = "NContact";

            variableTableInterface.AddVariable("operand", StorageType.Output);
            variableTableInterface.AddVariable("bit", StorageType.InOut);

            operand = variableTableInterface.GetVariableValue<PlcBool>("operand");
            bit = variableTableInterface.GetVariableValue<PlcBool>("bit");
        }

        public override IPlcMember GetInterfaceVariableByName(string name)
        {
            if (name == "pre") return EN;
            else if (name == "out") return ENO;
            else return variableTableInterface.GetVariableValue<IPlcMember>(name);
        }
        public bool outLogic()
        {
            if (operand == null || bit == null)
            {
                return false;
            }
            else
            {
                return operand.Value && !bit.Value;
            }
        }

    }
}
